package com.xiaoq.sites.service.impl;

import com.alibaba.dubbo.config.annotation.Service;
import com.xiaoq.apis.order.InterOrder4InterCalendarVo;
import com.xiaoq.apis.sites.ISitesApi;
import com.xiaoq.apis.sites.SitesInfo4Activity;
import com.xiaoq.apis.sites.SitesInfo4SocialVo;
import com.xiaoq.sites.entity.InterpreterCalendarEntity;
import com.xiaoq.sites.entity.SitesEntity;
import com.xiaoq.sites.repository.IInterpreterCalendarRepository;
import com.xiaoq.sites.repository.ISitesRepository;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;

@Service(interfaceClass=ISitesApi.class, version="1.0.0")
public class SitesApiImpl implements ISitesApi {

	private Logger logger = LoggerFactory.getLogger(SitesApiImpl.class);

	@Autowired
	private ISitesRepository repo;

	@Autowired
	private IInterpreterCalendarRepository interpreterCalendarRepository;
	
	@Override
	public SitesInfo4SocialVo getSiteInfo4Social(String id) {
		SitesEntity entity = repo.findById(id);
		if (entity == null) {
			return null;
		}
		SitesInfo4SocialVo vo = new SitesInfo4SocialVo();
		BeanUtils.copyProperties(entity, vo);
		return vo;
	}

	@Override
	public boolean save(InterOrder4InterCalendarVo interOrder4InterCalendarVo) {
		if(interOrder4InterCalendarVo != null){
			InterpreterCalendarEntity interpreterCalendarEntity = new InterpreterCalendarEntity();
			try {
				BeanUtils.copyProperties(interOrder4InterCalendarVo, interpreterCalendarEntity);
			}catch (Exception e){
				logger.error("保存InterpreterEntity失败." + e.getMessage());
				return false;
			}
			return interpreterCalendarRepository.save(interpreterCalendarEntity);
		}
		return false;
	}

	@Override
	public SitesInfo4Activity getSitesInfo4Activity(String id) {
		SitesEntity entity = repo.findById(id);
		if (entity == null) {
			return null;
		}
		SitesInfo4Activity vo = new SitesInfo4Activity();
		BeanUtils.copyProperties(entity, vo);
		return vo;
	}
}
